# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : 简单使用语言模型.py
# @Author: dongguangwen
# @Date  : 2025-03-23 15:09
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage, SystemMessage


model = ChatOpenAI(model="Pro-128K", api_key="dzCDkUHufCZEsuWlfVQd:",
                   base_url="https://spark-api-open.xf-yun.com/v1")

messages = [
    SystemMessage(content="Translate the following from English into Italian"),
    HumanMessage(content="hi!"),
]

ret = model.invoke(messages)
print(ret)

"""
content='Ciao!' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 3, 'prompt_tokens': 10, 'total_tokens': 13, 'completion_tokens_details': None, 'prompt_tokens_details': None}, 'model_name': None, 'system_fingerprint': None, 'id': None, 'finish_reason': None, 'logprobs': None} id='run-df82ec12-87f6-4d86-a383-e10ca9c7ff47-0' usage_metadata={'input_tokens': 10, 'output_tokens': 3, 'total_tokens': 13, 'input_token_details': {}, 'output_token_details': {}}
"""
